﻿using EFModel;
using IServices;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;

namespace Serives
{
    public class Teengage_interview : Iengage_interview
    {
        private readonly MyDBContext he;

        public Teengage_interview(MyDBContext he)
        {
            this.he = he;
        }
        //面试登记删除
        public Task<int> Delt(int id)
        {
            return Task.Run(() =>
            {
                engage_interview nv = he.engage_interview.Find(id);
                he.engage_interview.Remove(nv);
                int num = he.SaveChanges();
                return num;
            });
        }
        //简历登记删除
        public Task<int> DeltTo(int id)
        {
            return Task.Run(() =>
            {
                engage_resume nv = he.engage_resume.Find(id);
                he.engage_resume.Remove(nv);
                int num = he.SaveChanges();
                return num;
            });
        }
        //面试登记表添加
        public Task<int> Insert(engage_interview engage)
        {
            return Task.Run(() =>
            {
                he.engage_interview.Add(engage);
                int num = he.SaveChanges();
                return num;
            });
        }
        //简历查询
        public Task<ResultInfo> Query(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_resume.Where(e => e.interview_status ==1);
                var list = he.engage_resume
                    .Where(e => e.interview_status == 1)
                    .OrderBy(q => q.res_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //面试查询
        public Task<engage_interview> QueryTh(int id)
        {
            return Task.Run(() =>
            {
                return he.engage_interview.Find(id);
            });
        }
        //面试登记表查询
        public Task<ResultInfo> QueryTo(int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.engage_interview.Where(e=> e.check_status==0);
                var list = he.engage_interview
                    .Where(e => e.check_status == 0)
                    .OrderBy(q => q.ein_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //简历登记表面试状态修改
        public Task<int> Update(engage_resume resume)
        {
            return Task.Run(() =>
            {
                engage_resume engage_= he.engage_resume.Find(resume.res_id);
                engage_.interview_status = resume.interview_status;
                int num = he.SaveChanges();
                return num;
            });
        }
        //面试登记未通修改
        public Task<int> Updateset(engage_interview _Interview)
        {
            return Task.Run(() =>
            {
                engage_interview engage_ = he.engage_interview.Find(_Interview.ein_id);
                engage_resume engage_1 = he.engage_resume.Find(engage_.resume_id);
                engage_1.interview_status = 2;
                engage_.image_degree = null;
                engage_.native_language_degree = null;
                engage_.foreign_language_degree = null;
                engage_.response_speed_degree = null;
                engage_.EQ_degree = null;
                engage_.IQ_degree = null;
                engage_.multi_quality_degree = null;
                engage_.register = null;
                engage_.checker = null;
                engage_.interview_status = 2;
                engage_.interview_comment = null;
                engage_.interview_amount+=1;
                int num = he.SaveChanges();
                return num;
            });
        }
        //面试登记面试状态修改
        public Task<int> UpdateTo(engage_interview _Interview,string checker1, string check_time1)
        {
            return Task.Run(() =>
            {
                engage_interview engage_ = he.engage_interview.Find(_Interview.ein_id);
                engage_.checker = checker1;
                engage_.check_time = Convert.ToDateTime(check_time1);
                engage_.check_comment = _Interview.check_comment;
                engage_.interview_status = _Interview.interview_status;
                engage_.check_status = _Interview.check_status;
                int num = he.SaveChanges();
                return num;
            });
        }
    }
}
